from Entity import *

# For each cell of the map, there are an environment and maybe an entity           
class Cellule():
    def __init__(self):
        self.environment = None
        self.entity = None
    
    
    def __repr__(self):
        if(self.environment == 'water'):
            return 'water'
        if(self.entity == 'zombie'):
            return 'zombie'
        if(self.entity == 'human'):
            return 'human'
        if(self.entity == 'cop'):
            return 'cop'
        if(self.entity == 'berserk'):
            return 'berserk'
        if(self.entity == 'ZombieCop'):
            return 'ZombieCop'
        if(self.entity == 'OurZombie'):
            return 'OurZombie'
        else:
            return '.'
        
        
    def setEnvironment(self, env):
        self.environment = env
        
    def setEntity(self, e):
        self.entity = e   
        
        
# Representation of the Map. It used to store in memory the informations send from the server   
class Map:
    
    def __init__ (self, row, col):
        self.tab = [[Cellule() for x in xrange(row)] for x in xrange(col)]
        self.listHuman =[]
        self.row=row
        self.col=col

    def getRow(self):
        return self.row
    def getCol(self):
        return self.col
    def afficher_map(self):
        for j in self.tab:
            print j 

            
    def clear_map(self):
        for i in self.tab:
            for j in i:
                j.setEnvironment(None) 
                j.setEntity(None)

            
    def getInfo(self,row,col):
        infodir = []
        north=str(self.tab[row-1][col])
        south=str(self.tab[row+1][col])
        east=str(self.tab[row][col+1])
        west=str(self.tab[row][col-1])
        print 'On a pour notre zombie : '
        print 'North : ',north
        print 'South : ',south
        print 'East : ',east
        print 'West : ',west
        infodir.append(north)
        infodir.append(south)
        infodir.append(east)
        infodir.append(west)
        return infodir

# Setters of the representation of the Map (take 2 arguments : row & col)
    def setWater(self,row, col):            
        self.tab[row][col].setEnvironment("water")

    def setZombie(self, row, col, team):
        self.tab[row][col].setEntity("zombie")   
        
    def setOurZombie(self, row, col, ID):
        self.tab[row][col].setEntity("OurZombie")
        
        
    def setHuman(self, row, col, team):
        self.tab[row][col].setEntity("human")  
# self.listHuman.append(Human(type_human,team, row, col))

    def setCop(self, row, col, team):
        self.tab[row][col].setEntity("cop")  
         
    def setBerserk(self, row, col, team):
        self.tab[row][col].setEntity("berserk")
        
    def setZombieCop(self, row, col, team):
        self.tab[row][col].setEntity("ZombieCop") 
#main  
if __name__=="__main__":
    carte = Map(10,20)
    carte.setWater(4, 4)
    carte.setZombie(4, 6, 0)
    carte.setZombie(4, 8, 1)
    carte.afficher_map()
